package com.sxhuayuan.parking.controller.member;

import com.sxhuayuan.parking.config.PayStatus;
import com.sxhuayuan.parking.entity.Order;
import com.sxhuayuan.parking.service.OrderService;
import com.sxhuayuan.parking.service.ParkChannelService;
import com.sxhuayuan.parking.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller("memberAdvertController")
@RequestMapping("/member/advert")
public class AdvertController extends BaseController {

	@Autowired
	ParkChannelService exitService;
	@Autowired
	OrderService orderService;

	@RequestMapping("/get")
	public String advert(Model model, String orderSn) {
		// String exitsn = getExitSnFromSession();
		// ParkingLotExit exit = exitService.findBySn(exitsn);
		// if (exit != null) {
		//
		// }
		Order order = orderService.findBySn(orderSn);
		// 取消判断支付成功，因为支付回调稍微有点延迟的时候，用户跳转到这个界面时会显示错误页面，用户以为支付失败，会重复发起支付。
		// && order.getPayStatus() == PayStatus.success
		if (order != null) {
			model.addAttribute("paytime", DateUtils.format(order.getPaytime()));
			return "advert/advert";
		}
		return ERROR_VIEW;
	}

}
